package com.lib.application;

import com.lib.dto.CustomerApplyMessageDTO;
import com.lib.dto.RentalAgentQRCodeDTO;
import com.lib.dto.enums.CustomerMenuEnum;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by duqingxiang on 17/5/22.
 */
@Service
public class CustomerMessageService {

    @Autowired
    TemplateService templateService;
    @Autowired
    RentalAgentQRCodeService rentalAgentQRCodeService;


    public String getMenuBtnMessage(WxMpXmlMessage wxMessage,String menuKey) {

        CustomerMenuEnum menuEnum = CustomerMenuEnum.valuesOf(menuKey);

        switch (menuEnum) {
            case APPLY_TEXT:
                return this.getNormalMessage();
        }

        return null;
    }

    public String getNormalMessage(){

        return templateService.getTemplateContent(null, CustomerMenuEnum.APPLY_TEXT.getTemplate());
    }


    public String getScanQRCodeMessage(String openId,int param){

        // 根据二维码参数获取实际参数
        RentalAgentQRCodeDTO dto = rentalAgentQRCodeService.getRentalAgentQRCodeDTO(param);
        if (dto == null) {
            return null;
        }

        CustomerApplyMessageDTO messageDTO = CustomerApplyMessageDTO.builder()
                .name(dto.getAgent().getName())
                .phone(dto.getAgent().getPhone())
                .shop(dto.getAgent().getShopName())
                .agentId(dto.getAgent().getId())
                .openId(openId)
                .build();

        return templateService.getTemplateContent(messageDTO, CustomerMenuEnum.APPLY_SCAN_TEXT.getTemplate());
    }


}
